from lib.log.base import Logger
from lib.config.index import device_config
import sys

class ExceptionLogger(Logger):
    def __init__(self):
        super().__init__()
        self.__path = "/exception"
        self.__name = "exception log"

    def log(self, e):
        try:
            log_path = f"{self.get_log_path()}.log"

            if type(e) == str:
                super().write(e)
                return
            with open(log_path, "a+") as f:
                if device_config.is_debug():
                    sys.print_exception(e)
                sys.print_exception(e, f)
        except Exception as e:
            if device_config.is_debug():
                print(e)


